home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
MATHS
/
RLAB
/
RLAB125.ZIP
/
!RLaB
/
misc
/
gnupl_test
< prev
next >
Wrap
Text File
|
1995-10-16
|
6KB
|
290 lines
#
# Test 2-D plots
#
printf (" Have you got a gnuplot-3.5 patched with multiplot and border? (y/n) (def. no) ");
ans = getline ("stdin");
x = (0.25:4:.25)';
//-----------------------------------------------------------------//
autoscale();
title ("Multiple Line Colors and Styles");
linestyle ("line");
nogrid();
xlabel ("X-axis Label");
ylabel ("Y-axis Label");
plot ( [x, x, 2*x, 3*x] );
pause ("Type RETURN to continue");
title ("Multiple Point Colors and Styles");
linestyle ("point");
nogrid();
plot ( [x, x, 2*x, 3*x] );
pause ("Type RETURN to continue");
title ("Multiple Line-Point Colors and Styles");
linestyle ("linespoint");
grid();
plot ( [x, x, 2*x, 3*x] );
pause ("Type RETURN to continue");
title ("Multiple Line-Point Colors and Styles");
linestyle ("lines");
nogrid();
plot ( [x, x] );
linestyle ("point");
replot ( [x, 2*x] );
linestyle ("linespoint");
replot ( [x, 3*x] );
pause ("Type RETURN to continue");
nogrid();
//-----------------------------------------------------------------//
# Show off axis types
title("Linear Axes");
grid();
nolog();
plot ([x,exp(-x*0.5)]);
pause ("Type RETURN to continue");
title("Log X - Axis");
grid();
semilogx();
plot ([x,exp(-x*0.5)]);
pause ("Type RETURN to continue");
title("Log Y - Axis");
grid();
semilogy();
plot ([x,exp(-x*0.5)]);
pause ("Type RETURN to continue");
title("Log Axes");
loglog();
grid();
plot ([x,exp(-x*0.5)]);
pause ("Type RETURN to continue");
nolog();
nogrid();
//-----------------------------------------------------------------//
# Data with different scales
// y = (0.5:6:.2)';
// title("Plot Data with Different Scales");
// grid();
// plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
//pause ("Type RETURN to continue");
# Histograms
rand("normal", 0, pi);
r = rand(2000,1);
nogrid();
linestyle("boxes");
title("Histogram, Default No. of Bins");
hist (r);
pause ("Type RETURN to continue");
title("Histogram, 30 Bins");
nogrid();
hist (r, 30);
pause ("Type RETURN to continue");
title("2 Histograms, 30 Bins");
nogrid();
hist ([r, 2*r], 30);
pause ("Type RETURN to continue");
linestyle("lines");
title("2 Histograms, 30 Bins");
nogrid();
hist ([r, 2*r], 30);
pause ("Type RETURN to continue");
autoscale();
//-----------------------------------------------------------------//
# Make 3D data
# Sombrero
NX = 20;
NY = 20;
xx = zeros (1, NX);
yy = zeros (1, NY);
for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
zz = zeros (NX, NY);
for (i in 1:NX)
{
for (j in 1:NY)
{
r = sqrt (xx[i]^2 + yy[j]^2);
zz[i;j] = exp (-r * r) * cos (2*pi*r);
}
}
# Now create some plots
title("3-D Plot, Sombrero");
grid();
splot(xx,yy,zz);
pause ("Type RETURN to continue");
# Sin - Cos surface
x1 = -3:3:.2;
y1 = -3:3:.2;
z1 = zeros (x1.n, y1.n);
for (i in 1:x1.n)
{
for(j in 1:y1.n)
{
z1[i;j] = sin(y1[j]) * cos(x1[i]);
}
}
title("3-D Plot, Cos-Sine Surface");
nogrid();
splot(x1,y1,z1);
pause ("Type RETURN to continue");
# Slanted plane
x2 = 1:10;
y2 = 1:10;
z2 = zeros (x2.n, y2.n);
for (i in 1:x2.n) { z2[i;] = i*ones(1,y2.n); }
title("3-D Plot, Plane");
splot(x2,y2,z2);
pause ("Type RETURN to continue");
# Two Slanted planes
z3 = -2*z2;
title("3-D Plot, 2 - Planes");
splot(x2,y2,[z2',z3]);
pause ("Type RETURN to continue");
//-----------------------------------------------------------------//
#
# Simple contour plotting demonstration
#
NX = 20;
NY = 20;
xx = zeros (1, NX);
yy = zeros (1, NY);
for (i in 1:NX) { xx[i] = (i - NX/2)/(NX/2); }
for (i in 1:NY) { yy[i] = (i - NY/2)/(NY/2); }
zz = zeros (NX, NY);
for (i in 1:NX)
{
for (j in 1:NY)
{
r = sqrt (xx[i]^2 + yy[j]^2);
zz[i;j] = exp (-r * r) * cos (2*pi*r);
}
}
# Sin - Cos surface
x1 = -3:3:.2;
y1 = -3:3:.2;
z1 = zeros (x1.n, y1.n);
for (i in 1:x1.n)
{
for(j in 1:y1.n)
{
z1[i;j] = sin(y1[j]) * cos(x1[i]);
}
}
# Now create some plots
xlabel("X-Axis");
ylabel("Y-Axis");
title ("Contour Demonstration");
cont(xx,yy,zz);
pause ("Type RETURN to continue");
xlabel("X-Axis");
ylabel("Y-Axis");
title ("Contour Demonstration");
cont (x1,y1,z1);
pause ("Type RETURN to continue");
//-----------------------------------------------------------------//
#
# demonstrate replot, multiplot and plotyy.
#
x=0:10:0.1;
m1=[x',sin(x)'];
m2=[x',(cos(x)+1)'];
key();
title("a sin(x).");
plot(m1,["sin(x)"]);
pause("Type RETURN to continue");
title("cos(x)+1 added with a replot(data) command.");
replot(m2,["cos(x)+1"]);
pause("Type RETURN to continue");
if (ans.[1] == "y" || ans.[1] == "Y") {
title("Plot with txo y-axes");
plotyy();
key();
linestyle("lines");
ylabel("sin(x)");
plot(m1,["sin(x)"]);
ylabel("cos(x)+1");
plot(m2,["cos(x)+1"]);
pause("Type RETURN to continue");
nokey();
ylabel ("Y-axis");
multiplot(2,2);
linestyle("lines");
title("Sombrero");
splot(xx,yy,zz);
x = (0.25:4:.25)';
y = (0.5:6:.2)';
title("Different Scales");
grid();
plot (<< [x,exp(-x*0.5)] ; [y, exp (y*0.25), exp(y*0.1)] >>);
nogrid();
plotyy();
title("Plot with txo y-axes");
ylabel("sin(x)");
plot(m1);
ylabel("cos(x)+1");
plot(m2);
xlabel("");
ylabel("");
title("Contour plot");
cont(xx,yy,zz);
pause("Type RETURN to continue");
}
pclose(0);